<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>账单添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/font.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/layui/layui.js"
            charset="utf-8"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="layui-anim layui-anim-up">
<div class="x-body">
    <form class="layui-form" id="rechargeForm" onsubmit="return false">
        <input type="hidden" id="workerId" name="workerId" value="${worker.workerId}">
        <div class="layui-form-item">
            <label for="workerName" class="layui-form-label">
                <span class="x-red">*</span>操作员：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="workerName" name="workerName" required="" value="${worker.workerName}"
                       autocomplete="off" class="layui-input" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                <span class="x-red">*</span>账单类型：
            </label>
            <div class="layui-input-inline">
                <select name="billType" lay-verify="required">
                    <option value="0">支出</option>
                    <option value="1">收入</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="billMoney" class="layui-form-label">
                <span class="x-red">*</span>金额：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="billMoney" name="billMoney" required="" lay-verify="rechargeMoney"
                       autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label for="billAction" class="layui-form-label">
                <span class="x-red">*</span>备注：
            </label>
            <div class="layui-input-inline">
                <input type="text" id="billAction" name="billAction" required=""
                       autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label for="workerPassword" class="layui-form-label">
                <span class="x-red">*</span>密码确认：
            </label>
            <div class="layui-input-inline">
                <input type="password" id="workerPassword" name="workerPassword" required="" lay-verify="password"
                       autocomplete="off" class="layui-input" >
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
            </label>
            <button class="layui-btn" lay-filter="add" lay-submit="">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary" >重置</button>
        </div>
    </form>
</div>
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //自定义验证规则
        form.verify({
            password: [/(.+){6,12}$/, '密码必须6到12位'],
            rechargeMoney: [/^([1-9]\d*|0)(\.\d{1,2})?$/, '金额不能为空且最多保留两位小数！']
        });


        //监听提交
        form.on('submit(add)', function (data) {
            //发异步，把数据提交给java
            $.ajax({
                type: "post",
                url: "${pageContext.request.contextPath}/bill?m=addBill",
                data: data.field,
                dataType: "json",
                success: function (data) {
                    layer.msg(data.msg, function () {
                        if (data.code === 200) {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }
                    });

                }
            });
            return false;
        });

    });
</script>

</body>

</html>